package ${implPackage};

import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import ${pageVoJava};
import ${serviceJava};
import ${voJava};
import ${addDtoJava};
import ${changeDtoJava};
import ${listDtoJava};
import ${pageDtoJava};
import ${removeDtoJava};
import ${tbEntityPackage}.${tablePrefix}${clsName};
import ${tbMapperPackage}.${tablePrefix}${clsName}Mapper;
import ${tbServicePackage}.${tablePrefix}${clsName}Service;
import java.util.List;
import java.util.Date;
import javax.annotation.Resource;
import ${emptyUtilJava};
import ${beanUtilJava};

/**
 * ${tableComment} 服务实现类
 *
 * @author ${createUser}
 * @since ${createTime}
 */
@Service
public class ${implName} implements ${serviceName} {

    @Resource
    private ${tablePrefix}${serviceName} ${tablePrefix?uncap_first}${serviceName};

    @Resource
    private ${tablePrefix}${mapperName} ${tablePrefix?uncap_first}${mapperName};

    @Override
    public void add(${addDtoName} ${addDtoName?uncap_first}){
        //dto转换${tablePrefix?uncap_first}
        ${tablePrefix}${clsName} ${tablePrefix?uncap_first}${clsName} = BeanUtil.toModelClass(${addDtoName?uncap_first},${tablePrefix}${clsName}.class);
        //保存
        ${tablePrefix?uncap_first}${serviceName}.save(${tablePrefix?uncap_first}${clsName});
    }

    @Override
    public void remove(${removeDtoName} ${removeDtoName?uncap_first}){

        //根据id删除
        ${tablePrefix?uncap_first}${serviceName}.removeById("自己处理");
    }

    @Override
    public void change(${changeDtoName} ${changeDtoName?uncap_first}){
        //dto转换${tablePrefix?uncap_first}
        ${tablePrefix}${clsName} ${tablePrefix?uncap_first}${clsName} = BeanUtil.toModelClass(${changeDtoName?uncap_first},${tablePrefix}${clsName}.class);
        //修改
        ${tablePrefix?uncap_first}${serviceName}.updateById(${tablePrefix?uncap_first}${clsName});
    }

    @Override
    public List<${voName}> list(${listDtoName} ${listDtoName?uncap_first}){
        //dto转换${tablePrefix?uncap_first}
        ${tablePrefix}${clsName} ${tablePrefix?uncap_first}${clsName} = BeanUtil.toModelClass(${listDtoName?uncap_first},${tablePrefix}${clsName}.class);
        LambdaQueryWrapper<${tablePrefix}${clsName}> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.setEntity(${tablePrefix?uncap_first}${clsName});
        List<${tablePrefix}${clsName}> ${tablePrefix?uncap_first}${clsName}List = ${tablePrefix?uncap_first}${serviceName}.list(queryWrapper);
        //转换vo
        List<${voName}> ${voName?uncap_first}List = BeanUtil.toModelList(${tablePrefix?uncap_first}${clsName}List,${voName}.class);
        return ${voName?uncap_first}List;
    }

    @Override
    public PageVo<${voName}> page(${pageDtoName} ${clsName?uncap_first}){
        //获取iPage
        IPage<${tablePrefix}${clsName}> iPage = ${pageDtoName}.withPage(${clsName?uncap_first});
        //dto转换${tablePrefix?uncap_first}
        ${tablePrefix}${clsName} ${tablePrefix?uncap_first}${clsName} = BeanUtil.toModelClass(${clsName?uncap_first},${tablePrefix}${clsName}.class);
        LambdaQueryWrapper<${tablePrefix}${clsName}> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.setEntity(${tablePrefix?uncap_first}${clsName});
        //查询page
        IPage<${tablePrefix}${clsName}> ${tablePrefix?uncap_first}${clsName}Page = ${tablePrefix?uncap_first}${serviceName}.page(iPage,queryWrapper);
        //提取tbList
        List<${tablePrefix}${clsName}> ${tablePrefix?uncap_first}${clsName}List = ${tablePrefix?uncap_first}${clsName}Page.getRecords();
        PageVo<${voName}> ${voName?uncap_first}Page = null;
        if(EmptyUtil.isNotEmptyOfCollection(${tablePrefix?uncap_first}${clsName}List)){
            //${tablePrefix?uncap_first}List转voList
            List<${voName}> ${voName?uncap_first}List = BeanUtil.toModelList(${tablePrefix?uncap_first}${clsName}List,${voName}.class);
            //转pageVo
            PageVo<${tablePrefix}${clsName}> ${tablePrefix?uncap_first}${clsName}PageVo = PageVo.withIPage(${tablePrefix?uncap_first}${clsName}Page);
            ${voName?uncap_first}Page = PageVo.transform(${tablePrefix?uncap_first}${clsName}PageVo, ${voName?uncap_first}List);
        }
        return ${voName?uncap_first}Page;
    }
}